<?php
/**
 * @version     1.0.0
 * @package     com_agents
 * @copyright   Copyright (C) 2014. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Nguyen Thanh Trung <nttrung211@yahoo.com> - http://
 */

// No direct access.
defined('_JEXEC') or die;

require_once JPATH_COMPONENT.'/controller.php';

/**
 * Dailys list controller class.
 */
class AgentsControllerDailys extends AgentsController
{
	/**
	 * Proxy for getModel.
	 * @since	1.6
	 */
	public function &getModel($name = 'Dailys', $prefix = 'AgentsModel')
	{
		$model = parent::getModel($name, $prefix, array('ignore_request' => true));
		return $model;
	}
	
	function getDistricts(){
		$city_id = JRequest::getVar('city_id');
		$db = JFactory::getDBO();
		$db->setQuery("SELECT id, name FROM #__districts WHERE city_id=".$city_id);
		$districts = $db->loadObjectList();
		$html = '<select class="fl ml10" id="districts" onChange="changeDistrict(this.value)">
                    <option value="">Quận / Huyện</option>';
		foreach($districts as $district){
			$html .= '<option value="'.$district->id.'">'.$district->name.'</option>';
		}
		$html .= '</select>';
		
		echo $html;
		exit;
	}
	
	function getAgents(){
		$district_id = JRequest::getVar('district_id');
		$db = JFactory::getDBO();
		$db->setQuery("SELECT name, address, phone, lat, lng FROM #__agents WHERE district_id=".$district_id);
		$agents = $db->loadObjectList();
		$html = '';
		foreach($agents as $agent){
			$html .= '<li onClick="initialize('.$agent->lat.','.$agent->lng.')"><h3>'.$agent->name.'</h3><p>'.$agent->address.'<br>Tel: '.$agent->phone.'</p></li>';
		}

		echo $html;
		exit;
	}
}